package net.kucoe.grin.internal;

import java.util.ArrayList;

/**
 * List with limited size.
 * 
 * @author Vitaliy Basyuk
 * @param <E>
 */
public class LimitedList<E> extends ArrayList<E> {
    
    private static final long serialVersionUID = 6079202361484460717L;
    
    private final int maxSize;
    
    /**
     * Constructs LimitedList.
     * 
     * @param maxSize
     */
    public LimitedList(final int maxSize) {
        super();
        this.maxSize = maxSize;
    }
    
    public boolean add(final E e) {
        if (size() >= maxSize) {
            throw new IndexOutOfBoundsException("Max size: " + maxSize + ", Size: " + size());
        }
        return super.add(e);
    }
    
}
